package com.gxa.admin.recycling.service.impl;

import com.gxa.admin.recycling.mapper.AdviceMapper;
import com.gxa.admin.recycling.service.AdviceService;
import com.gxa.core.recycling.pojo.Advice;
import com.gxa.core.recycling.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author R
 * @data 2021-12-03 16:57
 */
@Service
public class AdviceServiceImpl extends BaseServiceImpl<Advice> implements AdviceService {

    @Autowired
    AdviceMapper mapper;


    @Override
    public List<Map<String, Object>> getAllAdvices(Integer page, Integer size) {
        List<Map<String, Object>> allAdvices = mapper.getAllAdvices((page - 1) * size, size);
        for (int i = 0; i < allAdvices.size(); i++) {
            if (allAdvices.get(i).get("creattime") != null) {
                String creattime = allAdvices.get(i).get("creattime").toString();
                allAdvices.get(i).put("creattime",creattime);
            }
        }

        return allAdvices;
    }

    @Override
    public Integer getAllAdvicesCount(Integer page, Integer size) {
        page = null;
        size = null;
        List<Map<String, Object>> allAdvices = mapper.getAllAdvices(page, size);
        return allAdvices.size();
    }

    @Override
    public Map<String, Object> getById(Integer id) {
        Map<String, Object> byId = mapper.getById(id);
        Object creattime = byId.get("creattime");
        if (creattime != null){
            byId.put("creattime",creattime.toString());
        }
        return byId;
    }
}
